//
//  ByWageListSecondCell.m
//  recordworktool_ios
//
//  Created by mc on 2018/4/10.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByWageListSecondCell.h"

@implementation ByWageListSecondCell

+ (instancetype)cellWithTableView:(UITableView*)tableView {
    
    static NSString *cellIdentifier = @"ByWageListSecondCell";
    ByWageListSecondCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
    
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self =  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self createViews];
    }
    return self;
}


- (void)createViews{
    
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    UIView *view = [[UIView alloc] init];
    [self.contentView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(10);
        make.right.equalTo(self.contentView).offset(-10);
        make.top.equalTo(self.contentView).offset(0);
        make.bottom.equalTo(self.contentView).offset(-5);
    }];
    view.backgroundColor = rgba(230, 246, 254, 1);
    view.layer.cornerRadius = 10;
    
    CGFloat width = (SCREEN_WIDTH - 20) / 4;
    UILabel *timeLabel = [[UILabel alloc] init];
    [view addSubview:timeLabel];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(view.mas_centerX).offset(0);
        make.centerY.equalTo(view).offset(0);
        make.size.mas_equalTo(CGSizeMake(width,20));
    }];
    timeLabel.textAlignment = NSTextAlignmentCenter;
    timeLabel.text = @"2017-10-9";
    timeLabel.font = FONT(12);
    timeLabel.textColor = TEXT_COLOR;
    
    UIButton *detailBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [view addSubview:detailBtn];
    [detailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(view).offset(-10);
        make.centerY.equalTo(view).offset(0);
        make.size.mas_equalTo(CGSizeMake(30, 22));
    }];
    detailBtn.titleLabel.font = FONT(12);
    [detailBtn setTitle:@"明细" forState:UIControlStateNormal];
    [detailBtn setTitleColor:BY_THEME_COLOR forState:UIControlStateNormal];
    [detailBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *nameLabel = [[UILabel alloc] init];
    [view addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view).offset(0);
        make.centerY.equalTo(view).offset(0);
        make.size.mas_equalTo(CGSizeMake(width, 20));
    }];
    nameLabel.font = FONT(12);
    nameLabel.textColor = TEXT_COLOR;
    nameLabel.text = @"王工头";
    nameLabel.textAlignment = NSTextAlignmentCenter;
    
    UILabel *priceLabel = [[UILabel alloc] init];
    [view addSubview:priceLabel];
    [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(detailBtn.mas_left).offset(-5);
        make.centerY.equalTo(view).offset(0);
        make.size.mas_equalTo(CGSizeMake(width - 5 - 40 - 5 + 20, 20));
    }];
    priceLabel.font = FONT(12);
    priceLabel.textColor = TEXT_COLOR;
    priceLabel.text = @"¥500";
    priceLabel.textAlignment = NSTextAlignmentCenter;
    
    UILabel *typeLabel = [[UILabel alloc] init];
    [view addSubview:typeLabel];
    [typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view.mas_centerX).offset(0);
        make.centerY.equalTo(view).offset(0);
        make.size.mas_equalTo(CGSizeMake(width - 20, 20));
    }];
    typeLabel.font = FONT(12);
    typeLabel.textColor = TEXT_COLOR;
    typeLabel.text = @"借支";
    typeLabel.textAlignment = NSTextAlignmentCenter;
    
    self.timeLabel = timeLabel;
    self.nameLabel = nameLabel;
    self.priceLabel = priceLabel;
    self.detailBtn = detailBtn;
    self.typeLabel = typeLabel;
}

- (void)btnAction:(UIButton *)btn{
    
    self.detailAction();
}

- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    if (BY_USER.isWorker.integerValue == 1) {
        self.nameLabel.text = _netModel.overseer_name;
    }else{
        self.nameLabel.text = _netModel.worker_name;
    }
    self.timeLabel.text = [NSDate getDateForStringFotmatWithTimeInterval:_netModel.create_time.integerValue formatter:@"yyyy-MM-dd"];
    self.priceLabel.text = [NSString stringWithFormat:@"¥%.2f",_netModel.money.floatValue];
    
    //点工
    if ([netModel.item_type_key isEqualToString:@"00S002003"]) {
        self.typeLabel.text = [NSString stringWithFormat:@"点工"];
        self.priceLabel.textColor = GREEN_COLOR;
        self.priceLabel.text = [NSString stringWithFormat:@"+¥%.2f",_netModel.money.floatValue];
    //包工
    }else if ([netModel.item_type_key isEqualToString:@"00S002002"]){
        self.typeLabel.text = [NSString stringWithFormat:@"包工"];
        self.priceLabel.textColor = GREEN_COLOR;
        self.priceLabel.text = [NSString stringWithFormat:@"+¥%.2f",_netModel.money.floatValue];
    //借支
    }else if ([netModel.item_type_key isEqualToString:@"00S002004"]){
        self.typeLabel.text = @"借支";
        self.priceLabel.textColor = GREEN_COLOR;
         self.priceLabel.text = [NSString stringWithFormat:@"+¥%.2f",_netModel.money.floatValue];
    //结算
    }else if ([netModel.item_type_key isEqualToString:@"00S002005"]){
        self.typeLabel.text = @"结算";
        self.priceLabel.textColor = GREEN_COLOR;
         self.priceLabel.text = [NSString stringWithFormat:@"+¥%.2f",_netModel.money.floatValue];
    }
}

@end
